//
//  MenuViewCell.m
//  YuDou
//
//  Created by qiupeng on 2018/6/24.
//  Copyright © 2018年 yingqi. All rights reserved.
//

#import "MenuViewCell.h"
#import "AnchorGroup.h"
#import "CollectionGameCell.h"

#define MenuViewCellID @"MenuViewCellID"

@interface MenuViewCell()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic ,weak) IBOutlet UICollectionView *collectionView;
@end


@implementation MenuViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
   
    self.autoresizingMask = UIViewAutoresizingNone;
    [self.collectionView registerNib:[UINib nibWithNibName:@"CollectionGameCell" bundle:nil] forCellWithReuseIdentifier:MenuViewCellID];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.minimumLineSpacing = 0;
    layout.minimumInteritemSpacing = 0;
    CGFloat itemW = self.collectionView.width / 4.0;
    CGFloat itemH = self.collectionView.height / 2.0;
    
    layout.itemSize = CGSizeMake(itemW, itemH);
    self.collectionView.collectionViewLayout = layout;

 }

- (void)setGroups:(NSArray<AnchorGroup *> *)groups
{
    _groups = groups;
    [self.collectionView reloadData];
}

#pragma mark - CollecetionView DataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _groups.count ? _groups.count : 0;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CollectionGameCell *cell = (CollectionGameCell *)[collectionView dequeueReusableCellWithReuseIdentifier:MenuViewCellID forIndexPath:indexPath];
    cell.game = _groups[indexPath.item];
    cell.clipsToBounds = YES;
    return cell;
}

@end
